local tianquan = fk.CreateSkill {
  name = "cf_tianquan",
  tags = { Skill.Lord, },
}

Fk:loadTranslationTable {
  ["cf_tianquan"] = "天权",
  [":cf_tianquan"] = "主公技，出牌阶段限一次，你可以令所有璃月角色议事。若议事有结果，意见与结果相同的角色摸两张牌，意见与结果不同的角色回复一点体力。",
}

local U = require("packages.utility.utility")

tianquan:addEffect("active", {
  can_use = function(self, player)
    return player:hasSkill(tianquan.name) and player:usedEffectTimes(self.name) == 0
  end,
  card_num = 0,
  target_num = 0,
  on_cost = function(self, player, data, extra_data)
    local room = player.room
    local tos = table.filter(room:getAlivePlayers(), function(element, index, array)
      return element.kingdom == "Liyue" and not element:isKongcheng()
    end)
    return { tos = tos, }
  end,
  on_use = function(self, room, skillUseEvent)
    local targets = skillUseEvent.tos
    local player = skillUseEvent.from
    local discussion = U.Discussion(player, targets, tianquan.name)
    if discussion.color == nil then return end
    for _, p in ipairs(targets) do
      if discussion.results[p].opinion == discussion.color then
        p:drawCards(2, tianquan.name)
      else
        room:recover({ who = p, num = 1, skillName = tianquan.name })
      end
    end
  end
})

return tianquan
